package com.qiaofei.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class House {

    private Integer id; //ID
    private Integer adminId;
    private String title;
    private Short estateId;
    private Short houseShi;
    private Short houseTing;
    private Short houseWei;
    private Short houseFloor;
    private Short houseFloorTotal;
    private String houseArea;
    private Short houseDir;
    private Short houseFitment;
    private Short houseDeposit;
    private LocalDate houseTime;
    private String housePrice;
    private String houseInfo;
    private String houseImages;
    private Short  state;

    private LocalDateTime createTime; //创建时间
    private LocalDateTime updateTime; //修改时间

    private String estateName;
    private String estateYear;
    private String estateInfo;

    public String getCreateTimeStr(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = Date.from(createTime.atZone(ZoneId.systemDefault()).toInstant());
        return format.format(date);
    }

    public String getUpdateTimeStr(){
        if(updateTime != null) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = Date.from(updateTime.atZone(ZoneId.systemDefault()).toInstant());
            return format.format(date);
        }
        return "";
    }

    public LocalDate getCreateDate() {
        LocalDate date = createTime.toLocalDate();
        return date;
    }

    public String getHousePriceStr() {
        return String.format("%s万元", housePrice);
    }

    public List<String> getHouseImagesList() {
        if(houseImages == null || houseImages.equals("")){
            return null;
        }else {
            String[] houseImagesList = houseImages.split(",");
            List<String> list = new ArrayList<>();
            for (String image :
                    houseImagesList) {
                list.add(String.format("/static/upload/%s", image));
            }
            return list;
        }
    }

    public String getFirstHouseImage() {
        List<String> houseImagesList = getHouseImagesList();
        if(houseImagesList != null && houseImagesList.size() > 0) {
            return houseImagesList.get(0);
        }
        return "";
    }

    public String getHouseFitmentStr() {
        List<String> houseFitmentList = Arrays.asList(new String[]{"毛坯房","简单装修","精装修"});
        return houseFitmentList.get(houseFitment-1);
    }

    public String getHouseDirStr() {
        List<String> houseDirList = Arrays.asList(new String[]{"东","南","西","北"});
        return houseDirList.get(houseDir-1);
    }

    public String getHouseDepositStr() {
        if(houseDeposit != null) {
            List<String> houseDepositList = Arrays.asList(new String[]{"押一付一", "押二付一", "押三付一"});
            return houseDepositList.get(houseDeposit - 1);
        }
        return "";
    }
}
